//
//  CCDetailViewModel.m
//  Party
//
//  Created by its on 15/3/27.
//  Copyright (c) 2015年 coco. All rights reserved.
//

#import "CCDetailViewModel.h"
#import "CCDetailModel.h"
@interface CCDetailViewModel()
@property (nonatomic, strong) CCDetailModel *model;
@end
@implementation CCDetailViewModel
- (id) initWithModel:(CCDetailModel *)model {
  if (self = [super init]) {
    _model = model;
  }
  return self;
}

- (RACSignal *) showDetail {
  RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    [subscriber sendNext: nil];
    RACDisposable *dispose = [[self.model requestDetail] subscribeNext:^(CCDetailResult *x) {
      _imageArray = x.images;
      _address = [[NSAttributedString alloc] initWithString:x.address.address attributes:@{}];
      _location = [[NSAttributedString alloc] initWithString:x.address.location attributes:@{}];
      _time = [[NSAttributedString alloc] initWithString:x.activityTime attributes:@{}];
      _content = [[NSAttributedString alloc] initWithString:x.description attributes:@{}];
      _title = [[NSAttributedString alloc] initWithString:x.title attributes:@{}];
      _replyCount = [NSString stringWithFormat:@"%@", x.replayCount];
    } error:^(NSError *error) {
      [subscriber sendError:error];
    } completed:^{
      [subscriber sendCompleted];
    }];
    RACCompoundDisposable *compoundDisposable = [RACCompoundDisposable compoundDisposable];
    [compoundDisposable addDisposable: dispose];
    return compoundDisposable;
  }];
  return signal;
}

@end
